<?php

namespace App\Http\Controllers;

use App\Http\Models\FightApply;
use Illuminate\Support\Facades\View;
use Illuminate\Http\Request;
use Redirect;
use Illuminate\Support\Facades\Session;

class FightController extends MessageController
{
    public $modelName = 'fight';

    public function index()
    {
        return view('layout/list', array('title' => '赛事列表', 'modelName' => 'game'));
    }

    public function getDetail($data)
    {
        $canJoin = FightApply::doCheck($data->FID);
        return View::make($this->modelName . "/detail", compact('data', 'canJoin'));
    }


    //约战编辑
    public function getEdit($data)
    {
        if ($data->FCustomerID != Session::get('customer_id')) {
            die('Access Denied!');
        }
        $applys = FightApply::getAoolys($data->FID); //获取约战申请信息
        return View::make($this->modelName . "/edit", compact('data', 'applys'));
    }

    public function doChange(Request $request)
    {
        $data = $request->all();
        $model = new FightApply();
        if ($model->doChange($data['FAID'], $data['FARes'])) {
            echo '1';
            die;
        } else {
            echo '0';
            die;
        }
    }


}
